import {
    getWaitingList, // 待领薪资
} from '../../api/get-paid'
import {
    clockInPageData,
    getUrgentInfo
} from '../../api/app'
import user from '../../utils/user'
import dayjs from 'dayjs'
const app = getApp()
Page({
    data: {
        srcolling: false,
        tipsflag: true,
        wagesList: [],
        totalMoney: '',
        toBePaid: 0,
    },
    onPageScroll(e) {
        this.setData({
            srcolling: true
        })
        if (this.data.timer) clearTimeout(this.data.timer)
        this.data.timer = setTimeout(() => {
            this.setData({
                srcolling: false
            })
        }, 1000)
    },
    showorclosetips() {
        this.setData({
            tipsflag: !this.data.tipsflag
        })
    },
    async onShow() {
        await user.waitLogin()
        const result = await getWaitingList()
        let num = 0
        result.record.forEach((item) => {
            num += item.paymentAmount * 100
            // let date = dayjs(item.payTime).parse('YYYYMMDDHHmmss')
            item.payTime = dayjs(item.payTime).format('YYYY-MM-DD')
        })
        this.setData({
            totalMoney: result.totalMoney,
            wagesList: result.record,
            toBePaid: num / 100
        })
        this.data.wagesList.forEach((item, index) => {
            this.setData({
                ['wagesList[' + index + '].createTime']: item.createTime.split(/[ ]+/)[0]
            })
        })
        await this.getUrgentInfo()
        this.setData({
            bankcard: user.bankCardNo
        })
    },
    // 获取个人信息
    async getUrgentInfo() {
        const result = await getUrgentInfo()
        this.data.idCardFront = result.idCardFront
    },
    goPath() {
        wx.navigateTo({
            url: '/pages/salary-details/salary-details'
        })
    },
    async goToPath(event) {
        let {
            id,
            bankcard,
            cards,
            index,
            applyid,
            salarycomeform
        } = event.target.dataset
        console.log(event.target.dataset, 'gidgid')
        if (event.target.dataset.salarycomeform === 0) {
            wx.navigateTo({
                url: `/pages/salary-list-details/salary-list-details?id=${id}&isCollectOpenBankAddress=${this.data.wagesList[index].isCollectOpenBankAddress}&isCollectOpenBankName=${this.data.wagesList[index].isCollectOpenBankName}&isCollectOpenBankCity=${this.data.wagesList[index].isCollectOpenBankCity}&isCollectBankCardImg=${this.data.wagesList[index].isCollectBankCardImg}`
            })
        } else if (event.target.dataset.salarycomeform === 1) {
            wx.navigateTo({
                url: `/packageAdvance/pages/advance-detail/advance-detail?id=${applyid}&isCollectOpenBankAddress=${this.data.wagesList[index].isCollectOpenBankAddress}&isCollectOpenBankName=${this.data.wagesList[index].isCollectOpenBankName}&isCollectOpenBankCity=${this.data.wagesList[index].isCollectOpenBankCity}&isCollectBankCardImg=${this.data.wagesList[index].isCollectBankCardImg}`,
            })
        }

    },
})